﻿/************************************************************
 * SessionId : 
 * 唯一的标志一个Session,辅助Session对象在Hash表中完成特定功能
 * ********************************************************/
namespace ZXW.DotNet.Common.Basic.Network.Tcp
{
    #region using
    using System;
    using System.Collections.Generic;
    using System.Text; 
    #endregion

    [Serializable]
    public class SessionId
    {
        private int _Id;

        /// <summary>与Session对象的Socket对象的Handle值相同,必须用这个值来初始化它</summary>
        public int Id
        {
            get { return _Id; }
            set { _Id = value; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="Id">与Session对象的Socket对象的Handle值相同</param>
        public SessionId(int Id)
        {
            this.Id = Id; 
        }

        public override bool Equals(object obj)
        {
            if (obj != null)
            {
                SessionId sId = (SessionId)obj;
                return _Id == sId._Id;
            }
            else if (this == null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>Hashtable键值特征</summary>
        public override int GetHashCode()
        {
            return this.Id;
        }

        /// <summary>显示输出</summary>
        public override string ToString()
        {
            return this.Id.ToString();
        }
    }
}
